//
//  IlPhotoViewController.m
//  IlPhoto
//
//  Created by 준기 반 on 11. 6. 5..
//  Copyright 2011 한성대학교. All rights reserved.
//

#import "IlPhotoViewController.h"
#import "toolClass.h"

@implementation IlPhotoViewController



/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/

-(void)effectButtonClick:(UIButton*)sender{
	UIImage* tempIMG;
	switch ([[sender titleForState:UIControlStateDisabled] intValue]) {
		case 0:
			tempIMG =sIMG;
			break;
		case 1:
			tempIMG=[toolClass imageFilter1:sIMG];
			break;
		case 2:
			tempIMG=[toolClass imageFilter2:sIMG];
			break;
		case 3:
			tempIMG=[toolClass imageFilter3:sIMG];
			break;
		case 4:
			tempIMG=[toolClass imageFilter4:sIMG];
			break;
		case 5:
			tempIMG=[toolClass imageFilter5:sIMG];
			break;
		case 6:
			tempIMG=[toolClass imageFilter6:sIMG];
			break;
		case 7:
			tempIMG=[toolClass imageFilter7:sIMG];
			break;
		case 8:
			tempIMG=[toolClass imageFilter8:sIMG];
			break;
		case 9:
			tempIMG=[toolClass imageFilter9:sIMG];
			break;
		case 10:
			tempIMG=[toolClass imageFilter10:sIMG];
			break;
		case 11:
			tempIMG=[toolClass imageFilter11:sIMG];
			break;
		case 12:
			tempIMG=[toolClass imageFilter12:sIMG];
			break;
		case 13:
			tempIMG=[toolClass imageFilter13:sIMG];
			break;
		case 14:
			tempIMG=[toolClass imageFilter14:sIMG];
			break;
		case 15:
			tempIMG=[toolClass imageFilter15:sIMG];
			break;
		case 16:
			tempIMG=[toolClass imageFilter16:sIMG];
			break;
		case 17:
			tempIMG=[toolClass imageFilter17:sIMG];
			break;
		case 18:
			tempIMG=[toolClass imageFilter18:sIMG];
			break;
		case 19:
			tempIMG=[toolClass imageFilter19:sIMG];
			break;
		case 20:
			tempIMG=[toolClass imageFilter20:sIMG];
			break;
		case 21:
			tempIMG=[toolClass imageFilter21:sIMG];
			break;
		case 22:
			tempIMG=[toolClass imageFilter22:sIMG];
			break;
		case 23:
			tempIMG=[toolClass imageFilter23:sIMG];
			break;
		case 24:
			tempIMG=[toolClass imageFilter24:sIMG];
			break;
		case 25:
			tempIMG=[toolClass imageFilter25:sIMG];
			break;
		case 26:
			tempIMG=[toolClass imageFilter26:sIMG];
			break;
		case 27:
			tempIMG=[toolClass imageFilter27:sIMG];
			break;
		case 28:
			tempIMG=[toolClass imageFilter28:sIMG];
			break;
		case 29:
			tempIMG=[toolClass imageFilter29:sIMG];
			break;
		default:
			tempIMG=sIMG;
			break;
	}
	[mainIMG setImage:tempIMG];

	NSLog(@"%@",sender.titleLabel.text);
	
	
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
    [super viewDidLoad];
	[self sethidden];

	
	
	////////////////
	UIView* effectView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
	for(int i = 0 ; i < 30 ; i++){
		UIButton* effectButton = [[UIButton alloc]initWithFrame:CGRectMake(i*80, 0, 80, 50)];
		[effectButton setBackgroundImage:[UIImage imageNamed:@"submenu.png"] forState:UIControlStateNormal];
		[effectButton setTitle:[NSString stringWithFormat:@"%d",i+1] forState:UIControlStateNormal];
		[effectButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
		[effectButton setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateDisabled];
		[effectButton addTarget:self action:@selector(effectButtonClick:) forControlEvents:UIControlEventTouchUpInside];
		[effectView addSubview:effectButton];
		[effectView setFrame:CGRectMake(0, 0, 80*(i+1), 50)];
	}
	[effectScroll addSubview:effectView];
	[effectScroll setContentSize:effectView.frame.size];

	
	
	///////////////
}



/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
	
}
-(void)sethidden{
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:1];
	[topView setCenter:CGPointMake(160,-45)];
	[bottomView setCenter:CGPointMake(160, 485)];
	//[mainView setAlpha:0.1];
	[UIView commitAnimations];
		//[centerButton setEnabled:YES];
	[centerButton setSelected:NO];
}
-(void)centerButtonEnable{
	[centerButton setEnabled:YES];
}
-(IBAction)centerClick{
	[centerButton setEnabled:NO];
	[NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(centerButtonEnable) userInfo:nil repeats:NO];
	NSLog(@"%d",centerButton.selected);
	if(centerButton.selected==NO){
//		[centerButton setEnabled:NO];
		[UIView beginAnimations:nil context:NULL];
		[UIView setAnimationDuration:1];
		[topView setCenter:CGPointMake(160,25)];
		[bottomView setCenter:CGPointMake(160, 435)];
		//[mainView setAlpha:0.1];
		[UIView commitAnimations];
		time = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(sethidden) userInfo:nil repeats:NO];
		[centerButton setSelected:YES];
	}else{
		[self sethidden];
		if(time!=nil){
			[time invalidate];
			
		}
	}

}
- (IBAction)pickIMG:(id)sender {
	
	imagePickerController=[[UIImagePickerController alloc]init];
	imagePickerController.delegate=self;
	imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
	[imagePickerController viewWillAppear:YES];
	[imagePickerController.view setCenter:CGPointMake(160, imagePickerController.view.center.y-20)];
	[self.view addSubview:imagePickerController.view];

	
	
}
- (IBAction)cameraPicker:(id)sender {
	NSLog(@"dsadsa");
	cameraPickerController=[[UIImagePickerController alloc]init];
	cameraPickerController.delegate=self;
	cameraPickerController.sourceType=UIImagePickerControllerSourceTypeCamera ;
	[cameraPickerController viewWillAppear:YES];
	[cameraPickerController.view setCenter:CGPointMake(160, cameraPickerController.view.center.y-20)];
	[self.view addSubview:cameraPickerController.view];
	NSLog(@"asdasd");
	
	
	
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	[imagePickerController viewWillDisappear:YES];
	[picker.view removeFromSuperview];

	
	
	[imagePickerController release];
	
	//MainScrollView.minimumZoomScale=1;
	
	
	
}
-(IBAction)save{
	UIImageWriteToSavedPhotosAlbum([mainIMG image], nil, nil, nil);
	[self alertPanel];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
	sIMG=image;
	[sIMG retain];
	[mainIMG setImage:image];
	[imagePickerController viewWillDisappear:YES];
	[picker.view removeFromSuperview];
	[imagePickerController release];
}
-(void)alertPanel{
	UIAlertView  *alertView = [[UIAlertView alloc]
							   initWithTitle:@"Compelete"
							   message:@""
							   delegate:nil
							   cancelButtonTitle:@"확인"
							   otherButtonTitles:nil];
	[alertView show];
	[alertView release]; 
}

@end
